package it.unicam.cs.cosy.bioshape.core.components;

import it.unicam.cs.cosy.bioshape.core.shapes.BoundingBox;

import javax.vecmath.Matrix3d;
import javax.vecmath.Matrix4d;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;

import vclip.ConvexPolyhedron;

/**
 * Entities to delimit a simulation volume. A Wall cannot move or rotate by any
 * means.
 * 
 * @author Gaston Alanis, Matteo Micheletti, Andrea Piermarteri, Federico Buti
 */
public class WallEntity extends ShapedEntity {

	private static final long serialVersionUID = 171637841734547892L;

	/**
	 * Generates a wall to delimit simulation. It is created as a box on the
	 * basis of the coordinates of the minimal and maximal points.
	 * 
	 * @param id
	 *            unique identifier for the wall
	 * @param min
	 *            minimal point of the wall
	 * @param max
	 *            maximal point of the wall
	 */
	public WallEntity(int id, Point3d min, Point3d max) {
		super(id, Double.POSITIVE_INFINITY, ConvexPolyhedron.createBox(max.x
				- min.x, max.y - min.y, max.z - min.z), new BoundingBox(min,
				max));
//		System.out.println("Created Wall entity " + getName());
//		System.out.println("PolyTree:");
//		System.out.println(this);
//	    System.out.println("Transformation matrix:");
//		System.out.println(getTransform());
//		System.out.println("Bounds:");
//		System.out.println(getBounds());
	}

	@Override
	public void move(double c) {
		// WALLS CANNOT MOVE!!
	}

	@Override
	public void updateVelocity() {
		// WALLS CANNOT MOVE!!
	}

	/**
	 * Moves the box to the specific position.
	 * 
	 * @param movement
	 *            The movement needed to set the wall in the right position
	 * 
	 */
	public void translate(Point3d movement) {
		Matrix4d matrix = getTransform();
		// new translation = previous one + the passed one
		matrix.m03 += movement.x;
		matrix.m13 += movement.y;
		matrix.m23 += movement.z;
		// update of the bounding box for collision detection (broad-phase)
		getBounds().moveTo(matrix.m03, matrix.m13, matrix.m23);
//		System.out.println("Moved Wall entity " + getName());
//        System.out.println("PolyTree:");
//        System.out.println(this);
//        System.out.println("Transformation matrix:");
//        System.out.println(getTransform());
//        System.out.println("Bounds:");
//        System.out.println(getBounds());
	}

	@Override
	protected void setServiceRequest() {
		// WALLS DO NOT PERCEIVE
	}

	@Override
	public ShapeRequest queryServices() {
		// WALLS DO NOT PERCEIVE
		return null;
	}

	@Override
	public void join(Entity entity) {
		// WALLS DO NOT JOIN OTHER ENTITIES
	}

	@Override
	public void split() {
		// WALLS DO NOT SPLIT BONDS
	}

	@Override
	public Matrix3d getInertiaTensor() {
		return new Matrix3d();
	}

	@Override
	public void setInstantVelocity(Vector3d t) {
		// WALLS CANNOT MOVE!!
	}

	@Override
	public void setInstantAngularVelocity(Vector3d t) {
		// WALLS CANNOT MOVE!!
	}
}